<?php
/**
 * Created by PhpStorm.
 * User: Inhere
 * Date: 15-4-9
 * Time: 上午10:08
 * Used: create html Element
 * file: AbstractField.php
 */

namespace ulue\libs\form;


class AbstractField
{

    public $type = 'text';

    public $name;

    public $value = null;

    public $id = null;

    public $wrap = 'div';


    /**
     * html code 分组
     * @var string
     */
    public $fieldset = null;

    /**
     * name 分组 MyForm[fieldname]
     * @var string
     */
    public $group = null;


    /**
     * Property trueValueMapping.
     *
     * @var  array
     */
    protected static $trueValueMapping = array(
        'readonly' => 'true',
        'disabled' => 'true',
        'multiple' => 'true',
        'checked'  => 'checked',
        'selected' => 'selected'
    );

    public function __construct()
    {
        # code...
    }

    public function getName($full=false)
    {
        if ($full) {
            return $this->group . '-' . $this->name;
        }

        return $this->name;
    }

    public function createId()
    {
        $this->id = ( $this->id ? $this->id .'-' : ''). $this->getName(true);
    }

}// end class AbstractField